  #!/bin/bash 
  . /etc/profile
  . ~/.bash_profile

   if [ $# -gt 1 ]
    then
 	echo "Usage: stop.sh or stop.sh \"forcely\" "
	exit
    fi

  cd  /home/ulss/project/dpl-data-redistribution

  ps -ef|grep dpl-data-redistribution |grep -v grep |grep Xms |awk '{print  "kill " $2}'|sh  

  stopcount=0

  while (true)
   do
      count=`ps -ef|grep dpl-data-redistribution |grep -v "grep"|grep Xms|grep -v grep |wc -l`
      if [ $count -lt 1 ]
        then 
          echo "stop the dpl-data-redistribution done "
          exit 0
      else
  	echo "the redistribution is running,just wait ..."
  	sleep 15
	stopcount=$(($stopcount+1))
	
	if [ $# == 1 ]
	 then
	  if [ $stopcount -gt 2 ] 
	     then	
	 	echo "now will send kill -9 to the redistribution ...."
		ps -ef|grep dpl-data-redistribution |grep -v grep |grep -v Xms |awk '{print  "kill -9 " $2}'|sh
	 fi 
      	fi
      fi
   done
